<?php
declare ( strict_types = 1 )
	;

namespace Distributed\Event;

use Distributed\Contract\IEvent;
use UntilDistributed\Log;
use Distributed\Group\TransGroupManage;
use Distributed\Group\TransactionManage;
use Communication\TxSocketData;
use UntilDistributed\Constant;

/**
 * 分发提交
 *
 * @author mg
 */
class ActionCommit extends AbstractEvent implements IEvent {
	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \Distributed\Contract\IEvent::parseEvent()
	 */
	public function parseEvent(int $fd): ?TxSocketData {
		$groupId = $this->data->transGroup->groupId;
		
		dump ( 'grop_id：' . $groupId );
		
		$socketData = & $this->data;
		
		Log::getInstance ()->info ( "txmanage commit start" );
		
		TransGroupManage::getInstance ()->updateGroupStatus ( $groupId, Constant::$tx_status_commit );
		
		
		TransactionManage::getInstance ()->commit ( $groupId );
		
		// TransGroupManage::getInstance()->updateItemStatus($groupId, $socketData->transaction,Constant::$tx_status_commit);
		
		Log::getInstance ()->info ( "txmanage commit end" );
		
		TransGroupManage::getInstance ()->delGroup ( $groupId );
		
		return TxSocketData::createResponse(Constant::$tx_complete_ok);
	}
}